package no.la58.scribbles.client.event;

import no.la58.scribbles.shared.ScribbleList;

import com.google.gwt.event.shared.EventBus;
import com.google.gwt.event.shared.EventHandler;
import com.google.gwt.event.shared.GwtEvent;

public class ScribblesUpdateEvent extends GwtEvent<ScribblesUpdateEvent.UpdateHandler> {

    public interface UpdateHandler extends EventHandler {
	public void onNewScribbles(ScribbleList scribbles);
    }

    public static final Type<UpdateHandler> TYPE = new Type<UpdateHandler>();

    private ScribbleList scribbles;

    @Override
    public Type<UpdateHandler> getAssociatedType() {
	return TYPE;
    }

    @Override
    protected void dispatch(UpdateHandler handler) {
	handler.onNewScribbles(scribbles);
    }

    public void setScribbles(ScribbleList scribbles) {
	this.scribbles = scribbles;
    }

    public ScribbleList getScribbles() {
	return scribbles;
    }

    public static void register(EventBus bus, UpdateHandler handler) {
	bus.addHandler(TYPE, handler);
    }
}
